home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / quintus / quintus0.lha / work / instdel_2.06.2 < prev    next >
Text File  |  1992-04-03  |  5KB  |  158 lines

  1. %%% INSTANCE DELETION
  2. %%% version 2.05.3 (based on instdel_18.4)
  3. %%%   added support for Quintus Prolog
  4. %%%   fixed inst_del so it actually deletes instances
  5. %%%   checked unit clauses in instance deletion when rewriting or replacement
  6. %%%   assumed no instance when UR strategy, not rewriting, and no replacement
  7. %%%   don't check for the following when delete_all_instances:
  8. %%%    2. if C is user supported, then D is user supported
  9. %%%    3. if C is backward supported, then D is backward supported.
  10. %%% version 2.06.2
  11. %%%   fixed Quintus Prolog existence error in instance deletion
  12.  
  13. %%%
  14. %%% Two options are provided:
  15. %%% delete_all_instances: If a clause C is an instance of another clause D,
  16. %%%    delete C.
  17. %%% delete_nf_instances: If a clause C is an instance of another clause D,
  18. %%%    then C is deleted if the following conditions hold:
  19. %%%    1. if C is not forward supported
  20. %%%    2. if C is user supported, then D is user supported
  21. %%%    3. if C is backward supported, then D is backward supported.
  22. %%% Apparently, both options can't be applied at the same time.
  23. %%% If both options are set, then delete_all_instances is in effect.
  24. %%%
  25. %%% Since we don't count ground literals for literal bound check,
  26. %%%    it is no longer true that literal_bound(1) will generate only
  27. %%%    unit clauses.
  28. %%%
  29.  
  30.      inst_del :-
  31.     cputime(T1),
  32.          inst_del_fail, 
  33.     physically_erase(sent_C),
  34.     cputime(T2),
  35.     T3 is T2 - T1,
  36.     write_line(5,'Instance Deletion(s): ',T3),
  37.     !, fail.
  38.  
  39.      inst_del_fail :-
  40.     delete_all_instances,
  41.     instdel, !.
  42.      inst_del_fail :-
  43.     delete_nf_instances,
  44.     instdel, !.
  45.  
  46. %%% If UR strategy is used, then no clauses are instances of another clauses,
  47. %%%    so we don't need to do instance deletion regardless of the settings.
  48. %%% If literal bound is set to 1, then we don't need to do instance deletion 
  49. %%%    regardless of the settings since no clauses are instances of another
  50. %%%    clauses.
  51.      instdel :-
  52.     not(replacement),
  53.     not(rwr(_,_,_,_)),
  54.     current_support(sup(_,_,_,1)).
  55.      instdel :-
  56.     const_list(Clist),
  57.     instdel_1(Clist).
  58.  
  59. %%% we assume that input clauses are not instances of any clause.
  60. %%% we take one clause sent_C, then check if it is deleted or not,
  61. %%%    if not, we put it as sent_c.
  62.      instdel_1(Clist) :-
  63.     not(instdel_1a),
  64.         clause(sent_C(cl(_,_,by([Ln11,Ln12|Lns1],V11,V11,Clist,_),0,
  65.                 CS1,CR1,CT1,_,_)),true,Ref1),
  66.     not(logically_erased(sent_C,Ref1)),
  67.         clause(sent_C(C2),true,Ref1), 
  68.     logically_erase(sent_C,Ref1),
  69.         instdel_ckinst([Ln11,Ln12|Lns1],CS1,CR1,CT1,C2),
  70.     fail.
  71.      instdel_1(Clist) :-
  72.         instdel_1a,
  73.         clause(sent_C(cl(_,_,by(Cn,V11,V11,Clist,_),0,
  74.                 CS1,CR1,CT1,_,_)),true,Ref1),
  75.     not(logically_erased(sent_C,Ref1)),
  76.         clause(sent_C(C2),true,Ref1), 
  77.     logically_erase(sent_C,Ref1),
  78.         instdel_ckinst(Cn,CS1,CR1,CT1,C2),
  79.     fail.
  80. %%% copy sent_c to sent_C.
  81.      instdel_1(_) :-
  82.     sentc_to_sentC_z.
  83.  
  84. %%% check if replacement or rewriting
  85.      instdel_1a :-
  86.     replacement,
  87.     rwr(_,_,_,_),
  88.         !.
  89.  
  90.      instdel_ckinst(Cn1,CS1,CR1,CT1,C1) :-
  91.     delete_all_instances,
  92.     instdel_ckinst_all(Cn1,CS1,CR1,CT1,C1), !.
  93.      instdel_ckinst(Cn1,CS1,CR1,CT1,C1) :-
  94.     delete_nf_instances,
  95.     instdel_ckinst_nf(Cn1,CS1,CR1,CT1,C1), !.
  96.  
  97. %%% For delete_all_instances.
  98.      instdel_ckinst_all(Cn1,CS1,CR1,CT1,_) :-
  99.     instdel_cl_inst(Cn1,CS1,CR1,CT1).
  100.      instdel_ckinst_all(_,_,_,_,C1) :-
  101.     assertz(sent_c(C1)).
  102.  
  103. %%% For delete_nf_instances.
  104.      instdel_ckinst_nf(Cn1,sp(S11,S12,0),CR1,CT1,_) :-
  105.     instdel_cl_inst(Cn1,sp(S11,S12,0),CR1,CT1).
  106.      instdel_ckinst_nf(_,_,_,_,C1) :-
  107.     assertz(sent_c(C1)).
  108.  
  109. %%% Check if the given clause is an instance of any sent_C or sent_c.
  110.      instdel_cl_inst(Cn1,CS1,CR1,CT1) :-
  111.     clause(sent_C(cl(_,_,by(Cn1,V21,V21,_,_),_,CS2,CR2,CT2,_,_)),true,Ref),
  112.     not(logically_erased(sent_C,Ref)),
  113.     instdel_cl_inst_2('C',CS1,CR1,CT1,Cn1,CS2,CR2,CT2).
  114.      instdel_cl_inst(Cn1,CS1,CR1,CT1) :-
  115.     sent_c(cl(_,_,by(Cn1,V21,V21,_,_),_,CS2,CR2,CT2,_,_)),
  116.     instdel_cl_inst_2('c',CS1,CR1,CT1,Cn1,CS2,CR2,CT2).
  117.  
  118. %%% If C is user supported and D is not, or C is backward supported and
  119. %%%    D is not, then we don't consider deletion.
  120.      instdel_cl_inst_2(sp(1,_,_),_,_,_,sp(0,_,_),_,_) :-
  121.     delete_nf_instances, !, fail.
  122.      instdel_cl_inst_2(sp(_,1,_),_,_,_,sp(_,0,_),_,_) :-
  123.     delete_nf_instances, !, fail.
  124. %%% The information in D should be changed by the information in C.
  125.      instdel_cl_inst_2(T,CS1,CR1,CT1,Cn1,CS2,CR2,CT2) :-
  126.     max_CS_ind(CS2,CS1,CS3,Up),
  127.     min_CR_ind(CR2,CR1,CR3,Up),
  128.     binary_max_ind(CT2,CT1,CT3,Up),
  129.     instdel_cl_inst_1(T,Up,Cn1,CS3,CR3,CT3).
  130.  
  131. %%% No new information, do nothing.
  132.      instdel_cl_inst_1(_,n,_,_,_,_) :- !.
  133. %%% The information of D has to be changed.
  134. %%% For sent_C.
  135.      instdel_cl_inst_1('C',_,Cn1,CS3,CR3,CT3) :-
  136.     clause(sent_C(cl(_,_,by(Cn1,V21,V21,_,_),_,_,_,_,_,_)),
  137.         true,Ref2),
  138.     (not(logically_erased(sent_C,Ref2)) -> (
  139.       clause(sent_C(cl(CSize2,CN2,BY2,CI2,_,_,_,F2,pr(PS2,PD2,PL2,_,PX2))),
  140.         true,Ref2),
  141.       logically_erase(sent_C,Ref2),
  142.       priority_NewPR(CR3,PR3),
  143.       maximum(PR3,PX2,PX3),
  144.       assertz(sent_C(cl(CSize2,CN2,BY2,CI2,CS3,CR3,CT3,F2,
  145.         pr(PS2,PD2,PL2,PR3,PX3))))
  146.     ); true).
  147. %%% For sent_c.
  148.      instdel_cl_inst_1('c',_,Cn1,CS3,CR3,CT3) :-
  149.     clause(sent_c(cl(_,_,by(Cn1,V21,V21,_,_),_,_,_,_,_,_)),
  150.         true,Ref2),
  151.     clause(sent_c(cl(CSize2,CN2,BY2,CI2,_,_,_,F2,pr(PS2,PD2,PL2,_,PX2))),
  152.         true,Ref2),
  153.     erase(Ref2),
  154.     priority_NewPR(CR3,PR3),
  155.     maximum(PR3,PX2,PX3),
  156.     assertz(sent_c(cl(CSize2,CN2,BY2,CI2,CS3,CR3,CT3,F2,
  157.         pr(PS2,PD2,PL2,PR3,PX3)))).
  158.